package com.zzc.plugin;

import java.util.Objects;

/**
 * 忽略kapt任务:kapt=true
 */
public class SwitchInfo {
    private String key;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private boolean enable;

    public SwitchInfo(String name, String key, boolean enable) {
        this.key = key;
        this.name = name;
        this.enable = enable;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SwitchInfo that = (SwitchInfo) o;
        return Objects.equals(key, that.key);
    }

    @Override
    public int hashCode() {
        return Objects.hash(key);
    }

    public static void main(String[] atc) {
        SwitchInfo info = new SwitchInfo("kapt=xxx #忽略kapt任务");
        System.out.println(info);
    }
    //忽略kapt任务:kapt=true
    public SwitchInfo(String text) {
        if (text != null && text.length() > 0) {
            String[] strs = text.split("=");
            if (strs.length >= 2) {
                this.key = strs[0];
                if (strs[1].contains("#")) {
                    String[] names = strs[1].split("#");
                    if (names.length == 2) {
                        this.name = names[1];
                    }
                }
                if (strs[1].contains("//")) {
                    String[] names = strs[1].split("//");
                    if (names.length == 2) {
                        this.name = names[1];
                    }
                }
                if (this.name == null) {
                    this.name = this.key;
                }
                this.enable = strs[1].contains("true");
            }
        }
    }


    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    @Override
    public String toString() {
        if (name == null || name.equals(key)) {
            return key + "=" + enable;
        }
        return key + "=" + enable;
    }
}
